﻿using SqlSugar;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicQuartz.Core.SqlSugarExtension
{
    public class SqlSugarDataBase
    {
        private static readonly object _lock = new object();
        static SqlSugarDataBase()
        {
            SqlSugarClients = new ConcurrentDictionary<string, Lazy<ISqlSugarClient>>();
        }
        private static ConcurrentDictionary<string, Lazy<ISqlSugarClient>> SqlSugarClients { get; }

        public static void Add(string name, Lazy<ISqlSugarClient> client)
        {
            SqlSugarClients.TryAdd(name, client);
        }

        public static ISqlSugarClient DB(string name)
        {
            var get = SqlSugarClients.TryGetValue(name, out var client);
            if (client == null)
            {
                return null;
            }

            return client.Value;
        }
    }



}
